package dawn.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import dawn.ioc.DefaultContext;
import dawn.service.Service;

public class DefaultServer extends DefaultContext {

	private static final Logger log = LoggerFactory.getLogger(Launcher.class);

	public void start() {

		// 初始化所有的service
		for (Service s : getServiceList()) {
			s.init();
			log.info(s.getClass().getName(), "has init.");
		}
		log.info("init success.");
	}

	public void loop() {
		log.info("server in loop");
		while (true) {
			for (Service s : getServiceList()) {
				s.update();
			}
		}
	}

	public void shutdown() {
		for (Service s : getServiceList()) {
			s.shutdown();
			log.info(s.getClass().getName(), "has shutdown.");
		}

		log.info("shutdown success.");
	}

}
